//
//  PhotosetInfo.m
//  iFlickr
//
//  Created by 张 霄鹤 on 09-7-3.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "PhotosetInfo.h"


@implementation PhotosetInfo

@synthesize setID;
@synthesize primary;
@synthesize secret;
@synthesize serverID;
@synthesize farmID;
@synthesize title;
@synthesize description;
@synthesize photos;
@synthesize url;
@synthesize image;

/**
 * 通过属性字段设置内容
 */
- (void)setProperties:(NSDictionary *)attribs{
	if(attribs){
		NSString *str = nil;
		str = [attribs objectForKey:@"id"];
		if(str){
			self.setID = str;
		}
		str = [attribs objectForKey:@"primary"];
		if(str){
			self.primary = str;
		}
	
		str = [attribs objectForKey:@"secret"];
		if(str){
			self.secret = str;
		}
	
		str = [attribs objectForKey:@"server"];
		if(str){
			self.serverID = str;
		}
	
		str = [attribs objectForKey:@"photos"];
		if(str){
			self.photos = [str intValue];
		}
	
		str = [attribs objectForKey:@"farm"];
		if(str){
			self.farmID = str;
		}
	
		str = [attribs objectForKey:@"url"];
		if(str){
			self.url = str;
		}
	
		str = [attribs objectForKey:@"title"];
		if(str){
			self.title = str;
		}
	
		str = [attribs objectForKey:@"description"];
		if(str){
			self.description = str;
		}
	}
}

/**
 * 获取图片地址
 */
- (NSString *)getPhotoURL:(NSInteger)picsize{
	char ch;
	NSString *ret;
	switch (picsize) {
		case PICSIZE_S:
			ch = 's';
			break;
		case PICSIZE_T:
			ch = 't';
			break;
		case PICSIZE_M:
			ch = 'm';
			break;
		case PICSIZE_B:
			ch = 'b';
			break;
		case PICSIZE_O:
			ch = 'o';
			break;
		default:
			ch = '\0';
			break;
	}
	if(ch == '\0'){
		ret = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@.jpg",self.farmID,self.serverID,self.primary,self.secret];
	}else{
		ret = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_%c.jpg",self.farmID,self.serverID,self.primary,self.secret,ch];
	}
	return ret;
}

@end
